<?php include("../config.php"); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title><?php echo $sitename; ?> - Sysop: Contact Developers</title>
<meta name="description" content="<?php echo $sitename; ?> - Sysop: Contact Developers">
<meta name="keywords" content="free to try, software, shareware, freeware, developers, vendors, download, PAD">
<meta name="author" content="Andrey Aleksanyants, M.D.">
<meta name="copyright" content="easy HTools">
<meta http-equiv="imagetoolbar" content="no">
<link rel="stylesheet" type="text/css" href="../<?php echo $cssfile; ?>">
<link rel="shortcut icon" href="../favicon.ico">
</head>
<body>
<table class="tmain" align="center" width="90%" cellspacing="0" cellpadding="0">
<tr>
<td class="tmain">
<table class="tlogo" align="center" width="100%" cellspacing="0" cellpadding="4">
<tr>
<td align="right">
<p><a href="index.php">Home</a></p>
</td>
</tr>
</table>
</td>
</tr><tr>
<td class="tmain">
<br>
<table align="center" width="100%" border="0" cellspacing="0" cellpadding="1">
<tr valign="top">
<td class="tbody">
<h1><?php echo $sitename; ?> - Sysop: Contact Developers</h1>
<?php

// Requesting form data
$comment = $_POST["comment"];
$submit  = $_POST["submit"];

if(empty($submit)) { // Displaying HTML form

	echo "<form action=\"" . $PHP_SELF . "\" method=\"post\">\n";
	echo "<table class=\"tvisible\" align=\"center\" cellSpacing=\"0\" cellPadding=\"4\">\n";
	echo "<tr>\n";
	echo "<td class=\"tdark\">\n";
	echo "<label for=\"progid\"><p><b>ProgID:</b></p></label></td>\n";
	echo "<td><p><input type=\"text\" class=\"text\" name=\"progid\" maxlength=\"7\"></p></td>\n";
	echo "</tr><tr>\n";
	echo "<td class=\"tdark\">\n";
	echo "<label for=\"comment\"><p><b>Your comment:</b></p></label></td>\n";
	echo "<td><p>Dear XXX!</p><br><textarea name=\"comment\" cols=\"45\" rows=\"5\">Your message text here...\n\nKind regards,\n\n" . $sitename . " download site webmaster,\nhttp://" . $_SERVER['HTTP_HOST'] . "\n</textarea></td>\n";
	echo "</tr><tr>\n";
	echo "<td class=\"tdark\"><p><b>Submit:</b></p></td>\n";
	echo "<td><input type=\"submit\" class=\"button\" name=\"submit\" value=\"   Submit   \"></td>\n";
	echo "</tr>\n</table></form><br>\n";

}
else { // Processing received data
	if(empty($progid)) { // If the ProgID field is empty
		$bad.= "You didn't specify the ProgID!<br>\n";
	}
	if(empty($comment)) { // If the Comment field is empty
		$bad.= "You didn't write your comment!<br>\n";
	}
	if($bad) { // If there was any problem with filling the form
		echo "<h2 class=\"red\">" . $bad . "</h2>\n";
		echo "<p><b>Please go <a href=\"javascript:history.back()\">Back</a> and fill the form correctly.</b></p>\n";
	}
	else { // Form is OK
		// Connecting to database
		if(!($link_id = mysql_connect($dbhost, $userid, $userpassword))) {
			die("<p><b>Error connecting to the database server:</b> " . mysql_error() . "</p>\n");
		}
		mysql_select_db($dbname);
		$result = mysql_query("SELECT * FROM paddata WHERE progid='$progid'", $link_id);
		$query = mysql_fetch_array($result);
		if(empty($query)) { // If there was no such entry in database
			die("<p><b>No such entry in database!</b></p>\n");
		}
		// Receiving the required information from paddata
		$contactname = $query["contactname"];
		$email       = $query["email"];
		$title       = $query["title"];
		
		// Sending notification email about rating
		$subject  = $title . " related";
		$message  = "Dear " . $contactname . "!\r\n\r\n";
		$message .= $comment . "\r\n";
		$headers  = "From: " . $sitename . "<" . $sitemail . ">\r\n";
		$headers .= "Reply-To: " . $sitename . "<" . $sitemail . ">\r\n";
		$headers .= "Bcc: " . $sitename . "<" . $sitemail . ">\r\n";
		$headers .= "Content-Type: text/plain; charset=windows-1252";
		if(mail($email, $subject, $message, $headers)) {
			echo "<p>Email successfully sent to " . $email . "</p>\n";
		}
		else {
			echo "<p>Error sending email to " . $email . "</p>\n";
		}
		
		// Disconnecting from database
		mysql_close($link_id);
	}
}
?>
<br>

</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>